package com.buer.storage.controller;

import com.buer.storage.dto.CarCategoryDto;
import com.buer.storage.entity.CarCategory;
import com.buer.storage.entity.CarCategorytwo;
import com.buer.storage.service.CarCategoryService;
import com.buer.storage.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/CarCategory")
public class CarCategoryController {
    @Resource
    private CarCategoryService carCategoryService;

    //增加车辆一级分类
    @PostMapping("/insertCarCategory")
    public R add(@RequestBody CarCategory carCategory) {
        if (carCategoryService.insertCarCategory(carCategory) > 0) {
            return R.setR(1, "添加车辆一级分类成功", null);
        }
        return R.setR(0, "添加车辆一级分类失败", null);
    }

    //删除车辆一级分类
    @GetMapping("/deleteCarCategoryById")
    public R delete(Integer categoryId) {
        if (carCategoryService.deleteCarCategoryById(categoryId) > 0) {
            return R.setR(1, "删除车辆一级分类成功", null);
        }
        return R.setR(0, "删除车辆一级分类失败", null);
    }

    //修改车辆一级分类
    @PostMapping("/updateCarCategoryById")
    public R update(@RequestBody CarCategory carCategory){
        if (carCategoryService.updateCarCategoryById(carCategory)>0){
            return R.setR(1,"修改车辆一级分类成功",null);
        }
        return R.setR(0,"修改车辆一级分类失败",null);
    }

    //查询所有车辆一级分类
    @GetMapping("/selectCarCategoryAll")
    public List<CarCategory> selectCarCategoryAll(){
        return carCategoryService.selectCarCategoryAll();
    }

    @GetMapping("/findCarCategoryAll")
    public List<CarCategoryDto> findCarCategoryAll(){
        List<CarCategoryDto> carCategoryAll = carCategoryService.findCarCategoryAll();
        return carCategoryAll;
    }

    @GetMapping("/selectCategorytwoById")
    public List<CarCategorytwo> selectCategorytwoById(Integer categoryId){
        List<CarCategorytwo> carCategorytwos = carCategoryService.selectCategorytwoById(categoryId);
        return carCategorytwos;
    }
}
